class User{
    id:number = 0;
    email:string;
    name:string;
    token:string;
}
export class AppGlobal {
    
    private static instance: AppGlobal = new AppGlobal();

    /**当前用户信息 */
    private user:User = new User();

    isLogin:boolean = false;

    static API_HOST:string = 'http://airbox.qryoga.com/api/v1'

    constructor() {
        if (AppGlobal.instance) {
            throw new Error("错误: 请使用AppGlobal.getInstance() 代替使用new.");
        }
        AppGlobal.instance = this;
    }

    /**
     * 获取当前实例
     * 
     * @static
     * @returns {AppGlobal}
     */
    public static getInstance(): AppGlobal {
        return AppGlobal.instance;
    }

    public login(params){
        this.isLogin = true;
        this.user.id = params.id;
        this.user.email = params.email;
        this.user.name = params.name;
        this.user.token = params.token;
        window['CurrUserToken'] = this.user.token;
    }

    public logout(){
        this.isLogin = false;
        this.user = new User();
    }

    public getUser(){
        return this.user;
    }
}